//window.onload=function(){
//	//searchByStationName();
//}
//function selectInput(oSelect) {
//    var area = oSelect.options[oSelect.selectedIndex].text;
//	//alert(area)
//	document.getElementById("ccid").value=area;
//}
//var map = new BMap.Map("container");
//    map.centerAndZoom("福州", 12);
//    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
//    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
//    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
//    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
//    map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开
//    var localSearchb = new BMap.LocalSearch(map);
//    localSearch.enableAutoViewport(); //允许自动调节窗体大小
//
//function searchByStationName() {
//    map.clearOverlays();//清空原来的标注
//   var areay = document.getElementById("text_b").value;
//		var key = document.getElementById("ccid").value;
//		document.getElementById("ccid2").value=key+areay;
//		var keywordb = document.getElementById("ccid2").value;
//	localSearchb.setSearchCompleteCallback(function (searchResult) {
//        var poi = searchResult.getPoi(0);
//        document.getElementById("result_b").value = poi.point.lng + "," + poi.point.lat;
//        document.getElementById("result_ab").value = poi.point.lng + "," + poi.point.lat;
//        map.centerAndZoom(poi.point, 13);
//        var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
//        map.addOverlay(marker);
//        var content = document.getElementById("text_b").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
//        var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
//        marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
//        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
//    });
//    localSearchb.search(keywordb);
//}

//上面的代码弃用，使用以下的模块
;(function(){

	var getGeocoder = (function(){
		var myGeo = null;
		if(!myGeo) myGeo = new BMap.Geocoder();
		return function(){
			return myGeo;
		}
	})();
	function getPoint(city,address,opt){
		var fn = new Function;
		var opt = opt || {};
		var success = opt.success || fn;
		var fail = opt.fail || fn;
		var error = opt.error || fn;
		if(!address || !city){
			error("缺省地址或城市");
			return false;
		}
		var gocoder = getGeocoder();
		gocoder.getPoint(address,function(point){
			if(point){
				success(point);
			}else{
				fail();
			}
		},city)
	}

	function init(){
		$("#text_b").on("blur",function(e){
			var address = $("#text_b").val();
			var city = $("#d_city").val();
			getPoint(city,address,{
				success : function(point){
					var lat = point.lat;
					var lng = point.lng;
					$("#result_ab").val(lng+" , "+lat);
				},
				fail : function(){},
				error : function(errorTxt){
					console && console.log(errorTxt);
				}
			});
		})
	}

	$(function(){
		init()
	})

})();

var LngLat = (function(){

	var getGeocoder = (function(){
		var myGeo = null;
		return function(){
			if(!myGeo) myGeo = new BMap.Geocoder();
			return myGeo;
		}
	})();
	function getByAddress(city,address,opt){
		var fn = new Function;
		var opt = opt || {};
		var success = opt.success || fn;
		var fail = opt.fail || fn;
		var error = opt.error || fn;
		if(!address || !city){
			error("缺省地址或城市");
			return false;
		}
		var gocoder = getGeocoder();
		gocoder.getPoint(address,function(point){
			if(point){
				success(point);
			}else{
				fail();
			}
		},city)
	}

	return{
		getByAddress : getByAddress
	}

})();
